package io.renren.service.impl;

import com.alibaba.fastjson.JSONObject;
import io.renren.entity.ServiceSettlementMainEntity;
import io.renren.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

import io.renren.dao.SalaryBasicinfoDao;
import io.renren.entity.SalaryBasicinfoEntity;
import io.renren.service.SalaryBasicinfoService;



@Service("salaryBasicinfoService")
public class SalaryBasicinfoServiceImpl implements SalaryBasicinfoService {
	@Autowired
	private SalaryBasicinfoDao salaryBasicinfoDao;
	
	@Override
	public SalaryBasicinfoEntity queryObject(Integer id){
		return salaryBasicinfoDao.queryObject(id);
	}
	
	@Override
	public List<SalaryBasicinfoEntity> queryList(Map<String, Object> map){
		return salaryBasicinfoDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return salaryBasicinfoDao.queryTotal(map);
	}
	
	@Override
	public void save(SalaryBasicinfoEntity salaryBasicinfo){
		salaryBasicinfoDao.save(salaryBasicinfo);
	}

	@Override
	public void update(SalaryBasicinfoEntity salaryBasicinfo){
		salaryBasicinfoDao.update(salaryBasicinfo);
	}
	
	@Override
	public void delete(Integer id){
		salaryBasicinfoDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		salaryBasicinfoDao.deleteBatch(ids);
	}

	@Override
	public List<SalaryBasicinfoEntity> getListByMap(Map<String, Object> map) {
		return salaryBasicinfoDao.getListByMap(map);
	}

	@Override
	public void updateTrailStatus(JSONObject jsonObject) {
		Calendar ca = Calendar.getInstance();
		String type = jsonObject.getString("type");
		String idss=  jsonObject.getString("ids") ;
		SysUserEntity user = (SysUserEntity)jsonObject.get("user");
		String[] ids = idss.substring(1,idss.length()-1).split(",");
		for (Object id : ids) {
			id = id.toString().substring(1, id.toString().length() - 1);
			SalaryBasicinfoEntity basic = salaryBasicinfoDao.queryObject(id);
			if("firTrial".equals(type)){
				if("0".equals(basic.getBasicStatus())){
					basic.setBasicFirstinstanceDate(ca.getTime());
					basic.setBasicFirstinstancePerson(user.getUsername());
					basic.setBasicStatus("1");
				}
			}else if("secTrial".equals(type)){
				if("1".equals(basic.getBasicStatus())){
					basic.setBasicFirstinstanceDate(ca.getTime());
					basic.setBasicFirstinstancePerson(user.getUsername());
					basic.setBasicStatus("2");
				}
			}
			else if("lastTrial".equals(type)){
				if("2".equals(basic.getBasicStatus())){
					basic.setBasicFirstinstanceDate(ca.getTime());
					basic.setBasicFirstinstancePerson(user.getUsername());
					basic.setBasicStatus("3");
				}
			}
			salaryBasicinfoDao.update(basic);
		}
	}

}
